package com.luych.toolbox.docker.service.sdk.network;

import com.luych.toolbox.docker.service.sdk.network.model.DockerNetworkConnectParam;
import com.luych.toolbox.docker.service.sdk.network.model.DockerNetworkDisconnectParam;
import com.luych.toolbox.docker.service.sdk.network.model.DockerNetworkInspectResult;
import org.springframework.web.client.RestTemplate;

public class DockerNetwork {

    private final String url;
    private final String id;

    public DockerNetwork(String url, String id) {
        this.url = url;
        this.id = id;
    }

    public DockerNetworkInspectResult inspect() {
        final String uri = url + "/networks/{id}";
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.getForObject(uri, DockerNetworkInspectResult.class, id);
    }

    public void remove() {
        final String uri = url + "/networks/{id}";
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.delete(uri, id);
    }

    public void connect(DockerNetworkConnectParam param) {
        final String uri = url + "/networks/{id}/connect";
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.postForObject(uri, param, String.class, id);
    }

    public void disconnect(DockerNetworkDisconnectParam param) {
        final String uri = url + "/networks/{id}/disconnect";
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.postForObject(uri, param, String.class, id);
    }

}
